using Xunit;

namespace CodePlex.TfsLibrary.Utility
{
    public class FileUtilTest
    {
        public class GetRelativePath
        {
            [Fact]
            public void BackwardTraversal()
            {
                string result = FileUtil.GetRelativePath(@"C:\Foo", @"C:\Foo\Bar\..\Bar");

                Assert.Equal("Bar", result);
            }

            [Fact]
            public void IdenticalPathsReturnsEmptyString()
            {
                string result = FileUtil.GetRelativePath(@"C:\Foo", @"C:\Foo");

                Assert.Empty(result);
            }

            [Fact]
            public void NonRelativePathReturnsFullPath()
            {
                string result = FileUtil.GetRelativePath(@"C:\Foo\Bar", @"C:\Foo");

                Assert.Equal(result, @"C:\Foo");
            }

            [Fact]
            public void NormalCase()
            {
                string result = FileUtil.GetRelativePath(@"C:\Foo", @"C:\Foo\Bar");

                Assert.Equal("Bar", result);
            }

            [Fact]
            public void TrailingSlashOnPath1()
            {
                string result = FileUtil.GetRelativePath(@"C:\Foo\", @"C:\Foo\Bar");

                Assert.Equal("Bar", result);
            }

            [Fact]
            public void TrailingSlashOnPath2()
            {
                string result = FileUtil.GetRelativePath(@"C:\Foo", @"C:\Foo\Bar\");

                Assert.Equal(@"Bar\", result);
            }
        }
    }
}